class Storage {
  constructor(key, isObject = false) {
    this.key = import.meta.env.MODE + '_' + key
    this.isObject = isObject
  }

  get() {
    let value = localStorage.getItem(this.key)

    if (this.isObject) {
      try {
        value = JSON.parse(value)
      } catch {
        value = null
      }
    }

    return value
  }

  set(value) {
    localStorage.setItem(this.key, this.isObject ? JSON.stringify(value) : value)
  }

  remove() {
    localStorage.removeItem(this.key)
  }
}

export const Token = new Storage('token')

export const UserInfo = new Storage('userInfo', true) // 用户信息

// export const isOperator = import.meta.env.MODE !== 'agent' // 运营后台

// export const isAgent = import.meta.env.MODE === 'agent' // 代理商后台
